﻿// ********************************************************************************************************
// Product Name: TestViewer.exe
// Description:  A very basic demonstration of the controls.
// ********************************************************************************************************
// The contents of this file are subject to the MIT License (MIT)
// you may not use this file except in compliance with the License. You may obtain a copy of the License at
// http://dotspatial.codeplex.com/license
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
// ANY KIND, either expressed or implied. See the License for the specific language governing rights and
// limitations under the License.
//
// The Initial Developer of this Original Code is Ted Dunsford. Created during refactoring 2010.
// ********************************************************************************************************
using System;
using System.ComponentModel.Composition;
using System.Windows.Forms;

using DotSpatial.Controls.Docking;

namespace MapWindow
{
    /// <summary>
    /// A Form to test the map controls.
    /// </summary>
    internal partial class MainForm : Form
    {
        // the main form is exported so that the IHeaderControl plug-in can add the menu or the
        // ribbon toolbar to it.
        [Export("Shell", typeof(ContainerControl))]
        private static ContainerControl Shell;

        /// <summary>
        /// Initializes a new instance of the <see cref="MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();
            LoadCustomBranding(Properties.Settings.Default);

            appManager.SatisfyImportsExtensionsActivated +=
                delegate(object sender, EventArgs e)
                {
                    // we use this event to ensure that legend and map dockable panels are
                    // added to the DockManager before any other dockable panels.
                    this.appManager.DockManager.Add(new DockablePanel("kMap", Properties.Resources.Map, map1, DockStyle.Fill) { SmallImage = MapWindow.Properties.Resources.map_16x16 });
                };

            Shell = this;
            appManager.LoadExtensions();

            this.appManager.ProgressHandler.Progress("", 0, Properties.Resources.GoToTheExtensionManagerToFindAdditionalExt);
        }

        private void LoadCustomBranding(Properties.Settings settings)
        {
            if (!String.IsNullOrWhiteSpace(settings.CustomAppIconPath) &&
                System.IO.File.Exists(settings.CustomAppIconPath))
            {
                System.Drawing.Icon ico = new System.Drawing.Icon(settings.CustomAppIconPath);
                this.Icon = ico;
            }

            if (!String.IsNullOrWhiteSpace(settings.CustomMainFormTitle))
            {
                this.Text = settings.CustomMainFormTitle;
            }
        }
    }
}